<template>
	<view class="shopping_order">
		<Navbar>提交订单</Navbar>
		<scroll-view scroll-y class="scroll_view">
			<view class="address">
				<view class="address_view" @click="router(`/pages/shopping/address`)">
					<image :src="`${baseImageUrl}/add/s4.png`"></image>
					<view class="address_deta" v-if="address.id">
						<view class="address_info">
							<view class="name">{{address.name}}</view>
							<view class="phone">{{address.phone}}</view>
						</view>
						<view class="text_deta">
							{{address.province}}{{address.city}}{{address.area}}{{address.address}}
						</view>
					</view>
					<text class="tips" v-else>请选择地址</text>
				</view>
				<u-icon name="arrow-right"></u-icon>
			</view>
			<view class="content">
				<image :src="cover" class="cover"></image>
				<view class="content_view">
					<view class="shopping_name">{{name}}</view>
					<view class="synopsis">{{synopsis}}</view>
					<view class="shopping_price">
						<view v-if="price>0">
							<text class="unit">￥</text>
							<!-- <image :src="`${baseImageUrl}/common/gy.png`" class="price_icon"></image> -->
							<text>{{price}}</text>
						</view>
						<view v-if="price_silver>0">
							<!-- <image :src="`${baseImageUrl}/add/s1.png`"></image> -->
							<image :src="`${baseImageUrl}/common/gy.png`" class="price_icon"></image>
							<text>{{price_silver}}</text>
						</view>
					</view>
				</view>
			</view>
			<view class="order_deta">
				<view>
					<view class="sub_title">
						<image :src="`${baseImageUrl}/home/xs.png`"></image>
						<text>订单详情</text>
					</view>
					<view class="item">
						<view class="key">购买数量：</view>
						<view class="value">X{{number}}</view>
					</view>
					<view class="item">
						<view class="key">订单金额：</view>
						<view class="total_price">
							<view v-if="price>0">
								<text class="unit">￥</text>
								<!-- <image :src="`${baseImageUrl}/common/gy.png`" class="price_icon"></image> -->
								<text>{{total_price}}</text>
							</view>
							<view v-if="price_silver>0">
								<!-- <image :src="`${baseImageUrl}/add/s1.png`"></image> -->
								<image :src="`${baseImageUrl}/common/gy.png`" class="price_icon"></image>
								<text>{{total_price_silver}}</text>
							</view>
						</view>
					</view>
				</view>

				<view>
					<view class="item_input">
						<view class="key">交易密码</view>
						<input type="text" password placeholder="请输入交易密码" v-model="pay_password" class="input">
					</view>
					<view class="btn" @click="submit">确认</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		shopProductInfo,
		shopOrderPlace
	} from '@/request/api.js';
	export default {
		data() {
			return {
				id: null,
				number: "",

				address: {
					id: null,
					name: "",
					phone: "",
					province: "",
					city: "",
					area: "",
					address: "",
				},

				cover: "",
				name: "",
				synopsis: "",
				price: "",
				price_silver: "",
				content: "",

				total_price: "",
				total_price_silver: "",

				pay_password: ""
			}
		},
		async onLoad(options) {
			this.number = options.n;
			let id = this.id = options.id;
			let {
				address,
				info
			} = await shopProductInfo({
				id
			});
			if (address) {
				this.address = address;
			}
			this.cover = info.cover;
			this.name = info.name;
			this.synopsis = info.synopsis;
			this.price = info.price;
			this.price_silver = info.price_silver;
			this.content = info.content;

			this.total_price = Number(this.price) * Number(this.number);
			this.total_price_silver = Number(this.price_silver) * Number(this.number);
		},
		methods: {
			async submit() {
				let {
					order_id
				} = await shopOrderPlace({
					product_id: this.id,
					number: this.number,
					pay_password: this.pay_password
				});
				this.router(`/pages/shopping/payment?id=${order_id}`);
				// this.router(`/pages/shopping/payment?id=${this.id}&n=${number}`);
				// this.$u.toast("验证码已发送,请查看");
			}
		}
	}
</script>

<style scoped lang="scss">
	.shopping_order {
		height: 100vh;
		background: #29170D;

		.scroll_view {
			height: calc(100vh - #{$navbarHeight});
			padding: 30rpx;
			box-sizing: border-box;

			.address {
				width: 100%;
				height: 146rpx;
				padding: 0 40rpx;
				box-sizing: border-box;
				background: url(#{$baseImageUrl}/add/bg5.png) no-repeat;
				background-size: 100% 100%;
				display: flex;
				justify-content: space-between;
				align-items: center;

				.address_view {
					flex: 1;
					display: flex;
					align-items: center;
					overflow: hidden;

					image {
						width: 50rpx;
						height: 50rpx;
					}

					.tips {
						color: #494338;
						font-size: 40rpx;
						font-weight: 400;
						font-family: LiSu;
						padding-left: 30rpx;
						box-sizing: border-box;
					}

					.address_deta {
						width: 100%;
						padding-left: 30rpx;
						box-sizing: border-box;
						overflow: hidden;

						.address_info {
							display: flex;
							align-items: center;

							.name {
								color: #494338;
								font-size: 40rpx;
								font-weight: 400;
								font-family: LiSu;
							}

							.phone {
								color: #494338;
								font-size: 30rpx;
								font-weight: 400;
								font-family: LiSu;
							}
						}

						.text_deta {
							width: 100%;
							color: #494338;
							font-size: 30rpx;
							font-weight: 400;
							font-family: LiSu;
							white-space: nowrap;
							text-overflow: ellipsis;
							overflow: hidden;
						}
					}
				}
			}

			.content {
				width: 100%;
				height: 288rpx;
				margin-top: 40rpx;
				margin-bottom: 10rpx;
				padding: 44rpx 40rpx 46rpx;
				box-sizing: border-box;
				background: url(#{$baseImageUrl}/add/bg6.png) no-repeat;
				background-size: 100% 100%;
				display: flex;

				.cover {
					width: 200rpx;
					height: 200rpx;
					border-radius: 10rpx;
				}

				.content_view {
					flex: 1;
					padding: 15rpx 0 10rpx 35rpx;
					box-sizing: border-box;
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					overflow: hidden;

					.shopping_name {
						color: #494338;
						font-size: 36rpx;
						font-weight: 400;
						font-family: LiSu;
					}

					.synopsis {
						color: #494338;
						font-size: 24rpx;
						font-weight: 500;
					}

					.shopping_price {
						display: flex;
						align-items: center;

						&>view {
							display: flex;
							align-items: center;

							&:first-child {
								margin-right: 10rpx;
							}

							.unit {
								color: #494338;
								font-size: 24rpx;
								font-weight: 400;
								font-family: LiSu;
							}

							image {
								width: 38rpx;
								height: 38rpx;

								&.price_icon {
									width: 30rpx;
									height: 30rpx;
								}
							}

							text {
								color: #494338;
								font-size: 32rpx;
								font-weight: 400;
								font-family: LiSu;
								padding-left: 6rpx;
								box-sizing: border-box;
							}
						}
					}
				}
			}

			.order_deta {
				width: 100%;
				height: 618rpx;
				padding: 46rpx 60rpx;
				box-sizing: border-box;
				background: url(#{$baseImageUrl}/add/bg7.png) no-repeat;
				background-size: 100% 100%;
				display: flex;
				flex-direction: column;
				justify-content: space-between;

				.sub_title {
					margin: 40rpx 0;
					display: flex;
					align-items: center;

					image {
						width: 32rpx;
						height: 32rpx;
					}

					text {
						line-height: 32rpx;
						color: #494338;
						font-size: 32rpx;
						font-weight: 400;
						font-family: SimSun;
						padding-left: 12rpx;
						box-sizing: border-box;
					}
				}

				.item {
					margin-bottom: 20rpx;
					display: flex;

					.key {
						color: #494338;
						font-size: 32rpx;
						font-weight: 400;
						font-family: SimSun;
					}

					.value {
						color: #494338;
						font-size: 32rpx;
						font-weight: 400;
						font-family: SimSun;
					}

					.total_price {
						display: flex;
						align-items: center;

						&>view {
							display: flex;
							align-items: center;

							&:first-child {
								margin-right: 10rpx;
							}

							.unit {
								color: #494338;
								font-size: 32rpx;
								font-weight: 400;
								font-family: LiSu;
							}

							image {
								width: 38rpx;
								height: 38rpx;

								&.price_icon {
									width: 30rpx;
									height: 30rpx;
								}
							}

							text {
								color: #494338;
								font-size: 32rpx;
								font-weight: 400;
								font-family: SimSun;
								padding-left: 6rpx;
								box-sizing: border-box;
							}
						}
					}
				}

				.item_input {
					.key {
						color: #494338;
						font-size: 32rpx;
						font-weight: 400;
						font-family: SimSun;
						margin-bottom: 20rpx;
					}

					.input {
						width: 100%;
						height: 80rpx;
						border-radius: 10rpx;
						padding-left: 45rpx;
						box-sizing: border-box;
						box-shadow: 2rpx -1px 10rpx 0px rgba(3, 0, 0, 0.2);
						background: #C0B5B6;
					}
				}

				.btn {
					width: 204rpx;
					height: 74rpx;
					line-height: 74rpx;
					text-align: center;
					color: #FFFFFF;
					font-size: 30rpx;
					font-weight: 400;
					font-family: SimSun;
					margin: 30rpx auto 0;
					background: url(#{$baseImageUrl}/common/btn.png) no-repeat;
					background-size: 100% 100%;
				}
			}
		}
	}
</style>